package com.shj.web.security.handler;

import com.shj.model.ResResult;
import com.shj.web.util.ResultUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO 登出成功处理类
 * @Author songhuajian
 * @Date 2020/3/13 0:05
 **/
@Component
public class UserLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        ResResult result = new ResResult();
        result.setCode(200);
        result.setMsg("登出成功");
        SecurityContextHolder.clearContext();
        ResultUtil.responseJson(response, result);
    }
}
